package com.jd.jr.insights.dm.dim.dao.impl;

import com.jd.jr.insights.dm.dim.dao.RuleDao;
import com.jd.jr.insights.dm.dim.dao.model.JfDimRule;
import com.jd.jr.insights.dm.dim.domain.Rule;
import com.jfinal.plugin.activerecord.Model;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class RuleDaoImpl implements RuleDao {


    public List<Rule> getList() {
        List<JfDimRule>JfDimRules =JfDimRule.dao.find("select * from jf_dim_rule");
        List<Rule> rules=new ArrayList<Rule>(JfDimRules.size());
        Iterator<JfDimRule> inter=JfDimRules.iterator();
        while(inter.hasNext()){
            JfDimRule ruleM=inter.next();
            Rule rule=new Rule(ruleM.getId()
                                    ,ruleM.getCode()
                                    ,ruleM.getValue()
                                    ,ruleM.getDesc()
                                    ,ruleM.getValue()
                                   ,ruleM.getIsValid()
                                   ,ruleM.getCreatedTime()
                                  ,ruleM.getUpdatedTime()
            );
           rules.add(rule);
        }

        return rules;
    }

    public List<Rule> getRuleDepartment_1_2List() {
        List<JfDimRule>JfDimRules =JfDimRule.dao.find("select * from jf_dim_rule where is_valid=1 and type=1 ");
        List<Rule> rules=new ArrayList<Rule>(JfDimRules.size());
        Iterator<JfDimRule> inter=JfDimRules.iterator();
        while(inter.hasNext()){
            JfDimRule ruleM=inter.next();
            Rule rule=new Rule(ruleM.getId()
                    ,ruleM.getCode()
                    ,ruleM.getValue()
                    ,ruleM.getDesc()
                    ,ruleM.getValue()
                    ,ruleM.getIsValid()
                    ,ruleM.getCreatedTime()
                    ,ruleM.getUpdatedTime()
            );
            rules.add(rule);
        }

        return rules;
    }

    public List<Rule> getRuleCategory_level_3List() {
        List<JfDimRule>JfDimRules =JfDimRule.dao.find("select * from jf_dim_rule where is_valid=1 and type=2");
        List<Rule> rules=new ArrayList<Rule>(JfDimRules.size());
        Iterator<JfDimRule> inter=JfDimRules.iterator();
        while(inter.hasNext()){
            JfDimRule ruleM=inter.next();
            Rule rule=new Rule(ruleM.getId()
                    ,ruleM.getCode()
                    ,ruleM.getValue()
                    ,ruleM.getDesc()
                    ,ruleM.getValue()
                    ,ruleM.getIsValid()
                    ,ruleM.getCreatedTime()
                    ,ruleM.getUpdatedTime()
            );
            rules.add(rule);
        }

        return rules;
    }

    public List<Rule>getRuleBusiness_sequence_4_7List() {
         List<JfDimRule>JfDimRules =JfDimRule.dao.find("select * from jf_dim_rule where is_valid=1 and type=3");
        List<Rule> rules=new ArrayList<Rule>(JfDimRules.size());
        Iterator<JfDimRule> inter=JfDimRules.iterator();
        while(inter.hasNext()){
            JfDimRule ruleM=inter.next();
            Rule rule=new Rule(ruleM.getId()
                    ,ruleM.getCode()
                    ,ruleM.getValue()
                    ,ruleM.getDesc()
                    ,ruleM.getValue()
                    ,ruleM.getIsValid()
                    ,ruleM.getCreatedTime()
                    ,ruleM.getUpdatedTime()
            );
            rules.add(rule);
        }

        return rules;
    }
}
